package org.hbbTlias2025.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


@Slf4j
@Component
public class DemoInterceptor implements HandlerInterceptor {

//    preHandle在目标方法之前执行，如果返回true，就代表放行，要是为false，就代表不放行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("这是demo拦截器————现在是执行一个超雄prehandle");
        return true;
    }


// 在目标资源执行之后执行，反正就是挺好，鉴定为还行
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("这是demo拦截器————现在是执行一个postHandle,执行完了执行");
    }


//    视图渲染之后进行运行，但是没啥卵用
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("这是demo拦截器————现在是执行一个afterCompletion,全都结束以后再运行");
    }
}
